package com.woniuxy.litener;

import com.woniuxy.config.RabbitConfig;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.Message;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
@Slf4j
public class LogDeadListener {

    @RabbitListener(queues = RabbitConfig.DEAD_LETTER_QUEUE)
    public void LogDeadHandle(Message message, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) Long tag){

        log.error("收到重试无法消费的日志数据，共 {} 条", message);

        try {
            channel.basicAck(tag, false);
            log.error("丢弃无法消费的日志数据，共 {} 条", message);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }


    }
}
